package lab3;

public class List implements IList {
	int val;
	IList next;
	
	public List( int i, IList next ){
		this.val = i;
		this.next = next;
	}

	@Override
	public IList addElt(int i) {		
		return new List(i, this);
	}

	@Override
	public int size() {
		return 1 + next.size();
	}
	
	public ISortedList sort() {
		ISortedList start = new SortedList( this.val, new EmptySortedList() );
		
		return next.addToSorted(start);
	}
	
	public String toString(){
		return val + ", " + next.toString();
	}

	@Override
	public ISortedList addToSorted(ISortedList list) {
		return this.next.addToSorted( list.addElt(this.val) );
	}
}
